package maMetrics;

import maConfigration.MetricSettings;

public abstract class MetricObject implements MetricsInterface{

	@SuppressWarnings("unused")
	
	protected float _nWeightGreen = 0;
	protected float _nWeightYellow = 0;
	protected float _nWeightRed = 0;
	
	protected int _nThresholdGreen = 0;
	protected int _nThresholdYellow = 0;
	protected int _nThresholdRed = 0;
	protected int _nThresholdTopList = 0;
	
	protected boolean _isApplyToProj = false;
	protected boolean _isApplyToPkg = false;
	protected boolean _isApplyToCls = false;
	protected boolean _isApplyToOp = false;
	protected boolean _isLogRawData = false;
	
	protected String _sMetricName = "";
	protected String _sMetricNameAb = "";
	
	public MetricObject(MetricSettings ms) {
		_isApplyToCls = ms.isApplyToCls();
		_isApplyToPkg = ms.isApplyToPkg();
		_isApplyToProj = ms.isApplyToProj();
		_isApplyToOp = ms.isApplyToOp();
		_isLogRawData = ms.isLogRawData();
		
		_nWeightGreen = ms.getWeightGreen();
		_nWeightYellow = ms.getWeightYellow();
		_nWeightRed = ms.getWeightRed();
			
		_nThresholdGreen = ms.getThresholdGreen();
		_nThresholdYellow = ms.getThresholdYellow();
		_nThresholdRed = ms.getThresholdRed();
		_nThresholdTopList = ms.getTopListBar();
		
		_sMetricNameAb = ms.getNameAb();

	}
	
	@Override
	public boolean isApplyToProj() {
		return _isApplyToProj;
	}

	@Override
	public boolean isApplyToPkg() {
		return _isApplyToPkg;
	}

	@Override
	public boolean isApplyToCls() {
		return _isApplyToCls;
	}
	
	@Override
	public boolean isApplyToItf() {
		return false;
	}

	@Override
	public boolean isApplyToOp() {
		return _isApplyToOp;
	}

	@Override
	public boolean isApplyToAttr() {
		return false;
	}
	
	@Override
	public boolean isLogRawData() {
		// TODO Auto-generated method stub
		return _isLogRawData;
	}
	
	@Override
	public void getLocalCfg(String str) {
		
	}

	@Override
	public void getGlobalCfg() {
		
	}
	
	@Override
	public float getWeightedValue(int n)
	{
		if(n >= _nThresholdGreen && n < _nThresholdYellow)
			return _nWeightGreen;
		else if(n >= _nThresholdYellow && n < _nThresholdRed)
			return _nWeightYellow;
		else if(n >= _nThresholdRed)
			return _nWeightRed;
		return 0;
	}
	
	@Override
	public int getRange(int n)
	{
		int ret = -1;
		
		if(n < _nThresholdGreen)
			ret = 0;
		else if(n >= _nThresholdGreen && n < _nThresholdYellow)
			ret = 1;
		else if(n >= _nThresholdYellow && n < _nThresholdRed)
			ret = 2;
		else if(n >= _nThresholdRed)
			ret = 3;
		
		return ret;
	}
	
	public MetricSettings getSettings()
	{
		return new MetricSettings(_isApplyToProj, _isApplyToPkg, _isApplyToCls, _isApplyToOp, _isLogRawData,
				_nThresholdRed, _nThresholdYellow, _nThresholdGreen, _nThresholdTopList,
				_nWeightRed, _nWeightYellow, _nWeightGreen, _sMetricNameAb);
	}
	
	public String getName()
	{
		return _sMetricName;
	}

}
